<?php 
/**
 * @author Eugenio Fage
 * http://eugeniofage.wordpress.com/
 * http://code.google.com/p/monky/
 * 
 */
 
$this->Html->script('theme/comment-vote',false);

$this->Paginator->options(array(
	'update'=>'#comments',
	'url'=>array('controller'=>'comments', 'action'=>'viewComments',$link['Link']['id']), 
    'before' => "$('#comments').html('<p>".$this->Html->image('loader.gif')."</p>');",
));
?> 
<h2><? printf(__('%d comments',true),$link['Link']['comment_count']) ?></h2>
<?
    	if($numbers=$this->Paginator->numbers(array('separator'=>' '))){
    		echo '<div class="commentPages">'.$this->Paginator->prev('« Previous ', null, null, array('class' => 'disabled')).
		 	$numbers.$this->Paginator->next(' Next »', null, null, array('class' => 'disabled')).'</div>';
    	}
    	
    	$i=0;
    	$offset=$this->Paginator->params['paging']['Comment']['options']['limit']*($this->Paginator->params['paging']['Comment']['options']['page']-1);
    	
    	foreach ($comments as $comment){
    		$i++;
    		echo $this->element('comments/comment',compact('comment','i','offset'));
    	} 
		
    	if($numbers=$this->Paginator->numbers(array('separator'=>' '))){
    		echo '<div class="commentPages">'.$this->Paginator->prev('« Previous ', null, null, array('class' => 'disabled')).
		 	$numbers.$this->Paginator->next(' Next »', null, null, array('class' => 'disabled')).'</div>';
    	}
    	if(isset($this->Js)) echo $this->Js->writeBuffer();
    	?>
  <h3>Add comment</h3>
  <div id="commentForm">
    <?
    $link_id=$link['Link']['id'];
    echo $this->element('comments/commentform',compact('link_id','error')); 
    ?>
  </div>
    
<?php $this->Html->scriptStart(array('allowCache'=>true,'safe'=>true,'inline'=>false)); ?>
DO_COMMENT_VOTE_URL='<?=Router::url(array('controller'=>'comments','action'=>'doVote')) ?>';
  
function highlight(elemId){
	if (elemId.indexOf('comment-') !=-1){
	  $('#comments div').removeClass('commentHighlight');
	  var elem = $(elemId);
      elem.addClass('commentHighlight');
    }
    $.scrollTo(elemId, {duration: 800, axis:"y"});
}
<?php 
echo $this->Js->domReady('if (document.location.hash) { highlight(document.location.hash); }
$("a[href*=#]").live("click",function(){
	var elemId = "#comment-" + $(this).attr("href").split("#")[1];
    highlight(elemId);
});

$("div.comment-body div a").live("click",function(){
  highlight("#comment-"+$(this).parent().parent().parent().attr("id"));
  return false;
})');

$this->Html->scriptEnd();
  ?>